home *** CD-ROM | disk | FTP | other *** search
/ The Fatted Calf / The Fatted Calf.iso / Applications / Graphics / Gnuplot / Source / SubCell.m < prev    next >
Encoding:
Text File  |  1993-03-18  |  3.1 KB  |  147 lines

  1.  
  2. static char RCSId[]="$Id: SubCell.m,v 1.1.1.1 1993/03/18 03:36:07 davis Exp $";
  3.  
  4.  
  5. /*  
  6.  *  Based on CustomCell in the NeXT Developer Example ScrollDoodScroll 
  7.  *  by Jayson Adams.
  8.  */
  9.  
  10. #import <appkit/Font.h>
  11. #import <appkit/NXImage.h>
  12. #import <appkit/Text.h>        /* NXTextFontInfo()        */
  13.  
  14. #import <dpsclient/wraps.h>
  15.  
  16. #import "SubCell.h"
  17. #import "SubObject.h"
  18.  
  19.  
  20. #define FIRST_COLUMN_START 4.0
  21. #define TEXT_COLUMN_START 20.0
  22.  
  23.  
  24. @implementation SubCell
  25.  
  26. static id     attachmentImage = 0;
  27. static NXSize    imageSize;
  28.  
  29. - init
  30. {
  31.     [super init];
  32.  
  33.     /* get the "attachment" image */
  34.     if (!attachmentImage) {
  35.     attachmentImage = [NXImage findImageNamed:"Attachment"];
  36.     [attachmentImage getSize:&imageSize];
  37.     }
  38.  
  39.     [self setStringValue:""];
  40.     return self;
  41. }
  42.  
  43.  
  44. /*  
  45.  *  Every SubCell is associated with a SubObject which stores the 
  46.  *  information that the SubCell displays.  When the SubObject is set, 
  47.  *  we set our instance variables to match it.
  48.  */
  49. - setSubObject:anObject
  50. {
  51.     const char *aString;
  52.  
  53.     if (anObject) {
  54.     subObject = anObject;
  55.     aString = [subObject stringValue];
  56.     [self setStringValue: aString? aString: ""];
  57.     showAttachment = [subObject isAttachment];
  58.  
  59.     return self;
  60.     } else
  61.     return nil;
  62. }
  63.  
  64.  
  65. - subObject
  66. {
  67.     return subObject;
  68. }
  69.  
  70.  
  71. - setFont:fontObj
  72. {
  73.     [super setFont:fontObj];
  74.     /*
  75.      *  Save this info so we don't have to look it up every time we 
  76.      *  draw.  Note:  "support" for a TextFieldCell is a font object.
  77.      */
  78.     NXTextFontInfo(support, &ascender, &descender, &lineHeight);
  79.  
  80.     return self;
  81. }
  82.  
  83.  
  84.  
  85. - drawInside:(const NXRect *)cellFrame inView:controlView
  86. {
  87.     NXPoint    imageOrigin;
  88.     NXRect    rectArray[2];
  89.     
  90.     /*  Set the font according to our drawing status.  */
  91.     if (NXDrawingStatus != NX_DRAWING) {
  92.     [support set];
  93.     } else {
  94.     [[support screenFont] set];
  95.     }
  96.     
  97.     /*  Erase the cell.  */
  98.     PSsetgray((cFlags1.state || cFlags1.highlighted) ? NX_WHITE : NX_LTGRAY);
  99.     NXRectFill(cellFrame);
  100.  
  101.     /*  Draw the "attachment" image, if the SubObject wants us to.  */
  102.     if (showAttachment) {
  103.     imageOrigin.x = FIRST_COLUMN_START;
  104.     imageOrigin.y = NX_Y(cellFrame) + NX_HEIGHT(cellFrame) - 1
  105.                 - (NX_HEIGHT(cellFrame) - imageSize.height) / 2.0;
  106.     [attachmentImage composite:NX_PLUSD toPoint:&imageOrigin];
  107.     }
  108.       
  109.     /*  Draw the text.  */
  110.     PSsetgray(NX_BLACK);
  111.     PSmoveto(NX_X(cellFrame) + TEXT_COLUMN_START,
  112.              NX_Y(cellFrame) + lineHeight - descender);
  113.     PSshow(contents);
  114.     
  115.     /*  Draw the two dark gray lines above and below the cell.  */
  116.     PSsetgray(NX_DKGRAY);
  117.     if (cFlags1.state || cFlags1.highlighted) {
  118.     /*
  119.      *  Draw 1-pixel-high rectangles instead of lines (this is 
  120.      *  faster than PSmoveto(); PSlineto()).
  121.      */
  122.     NXSetRect(&(rectArray[0]), NX_X(cellFrame), NX_Y(cellFrame),
  123.           NX_WIDTH(cellFrame), 1.0);
  124.     NXSetRect(&(rectArray[1]), NX_X(cellFrame), NX_MAXY(cellFrame) - 1.0,
  125.           NX_WIDTH(cellFrame), 1.0);
  126.  
  127.     /*  
  128.      *  Using NXRectFillList is faster than separate calls to 
  129.      *  NXRectFill.
  130.      */
  131.     NXRectFillList(rectArray, 2);
  132.     }
  133.  
  134.     return self;
  135. }
  136.  
  137.  
  138.  
  139. // Shuts up the compiler about unused RCSId
  140. - (const char *) rcsid
  141. {
  142.     return RCSId;
  143. }
  144.  
  145.  
  146. @end
  147.